var filechooser = document.getElementById("filePath");
  //    用于压缩图片的canvas
  var canvas = document.createElement("canvas");
  var ctx = canvas.getContext('2d');
  //    瓦片canvas
  var tCanvas = document.createElement("canvas");
  var tctx = tCanvas.getContext("2d");
  var maxsize = 100 * 1024;
  $("#upload").on("click", function() {
    filechooser.click();
  })
  .on("touchstart", function() {
	  $(this).addClass("touch")
  })
  .on("touchend", function() {
	  $(this).removeClass("touch")

  });
  
	 function showImage() {
        var docObj = document.getElementById("filePath");
       // var imgObjPreview = document.getElementById("preview");
        //console.log("docObj.files:"+docObj.files[0]);
        //console.log("docObj.files:"+docObj.files[1]);
       // console.log("docObj.files:"+docObj.files.length)
        var $imgLength = $(".img-list").children().length-1;
        var $num = 3-$imgLength;
        if(docObj.files.length > 3 || $imgLength>=3 || (docObj.files.length+$imgLength)>3){
		    alert("最多只能选择三个图片,你还能上传"+ $num +"个图片")
		    return false;
		}	
        for(var i =0; i<docObj.files.length; i++){
        	if (docObj.files && docObj.files[i]) {
	            //火狐下，直接设img属性  
	            /* imgObjPreview.style.display = 'block';
	            imgObjPreview.style.width = '200px';
	            imgObjPreview.style.height = '120px';
	            //imgObjPreview.src = docObj.files[0].getAsDataURL();  
	            //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式  
	            imgObjPreview.src = window.URL.createObjectURL(docObj.files[i]); */
	            var srcUrl = window.URL.createObjectURL(docObj.files[i]);
	            var html  = "<li><img src='"+srcUrl+"' class='contentI'/></li>";
	            $(".img-list").prepend(html);
	        } else {
	            //IE下，使用滤镜  
	            docObj.select();
	            var imgSrc = document.selection.createRange().text;
	            var localImagId = document.getElementById("localImag");
	            //必须设置初始大小  
	            localImagId.style.width = "100px";
	            localImagId.style.height = "100px";
	            //图片异常的捕捉，防止用户修改后缀来伪造图片 
	            try {
	                localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
	                localImagId.filters
	                        .item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
	            } catch (e) {
	                alert("您上传的图片格式不正确，请重新选择!");
	                return false;
	            }
	         //   imgObjPreview.style.display = 'none';
	            document.selection.empty();
	        }
        }
        
           $("#uploadImage").ajaxSubmit({
			        type: 'post',
			        url: rootPath+'/consultComment/addConsultCommentPic',
			      /*   beforeSubmit: function () {
			            var file = $("#filePicture").val();
			            var file2 = $("#filePicture").val();
			            var file3 = $("#filePicture").val();
			            var file4 = $("#filePicture").val();
			            return true;
			        }, */
			        success:function(data,status){
			        	if(data.resultSuccess == true){
			        		var filePicture = data.filePicture;
							if(filePicture!=null && filePicture!=undefined){
								console.log(filePicture)
								$("#filePicture").val(filePicture);
							}
							var filePicture2 = data.filePicture2;
							if(filePicture2!=null && filePicture2!=undefined){
								 console.log(filePicture2);
								$("#filePicture2").val(filePicture2);
							}
							var filePicture3 = data.filePicture3;
							if(filePicture3!=null && filePicture3!=undefined){
								console.log(filePicture3)
								$("#filePicture3").val(filePicture3);
							}
			        	}else{
			        		alert("上传失败")
			        	}
					},
					error:function(xhr,status,e){
						$.messager.alert('异常提示:',e,'error'); 
					}
			    });
        return true;
    }
